package com.xbongbong.pro.enums;

import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.SelectProductEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.*;
import com.xbongbong.saas.enums.product.CostAdjustProductEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author 吴峰
 * @date 2020/08/13 13:59
 */
@Getter
public enum SystemFieldFormulaEnum {

    /**
     * 系统字段公式
     */
    CONTRACT(XbbRefTypeEnum.CONTRACT.getCode(), Arrays.asList(ContractEnum.AMOUNT.getAttr(), ContractEnum.PRODUCT_TOTAL.getAttr(),
            ContractEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.SUBTOTAL.getAttr(),
            ContractEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.SELLING_PRICE.getAttr(),
            ContractEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.DISCOUNT.getAttr())),
    // 报价单
    QUOTATION(XbbRefTypeEnum.QUOTATION.getCode(), Arrays.asList(QuotationEnum.AMOUNT.getAttr(), QuotationEnum.PRODUCT_TOTAL.getAttr(),
            QuotationEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.SUBTOTAL.getAttr(), QuotationEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.SELLING_PRICE.getAttr(),
            QuotationEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.DISCOUNT.getAttr())),
    // 退货退款
    REFUND(XbbRefTypeEnum.REFUND.getCode(), Arrays.asList(RefundEnum.RETURN_AMOUNT.getAttr(),
            RefundEnum.PRODUCTS.getAttr() + StringConstant.POINT + SelectProductEnum.SUBTOTAL.getAttr())),
    // 退货单
    RETURN(XbbRefTypeEnum.RETURN.getCode(), Arrays.asList(ReturnEnum.RETURN_AMOUNT.getAttr(),
            ReturnEnum.PRODUCTS.getAttr() + StringConstant.POINT + SelectProductEnum.SUBTOTAL.getAttr())),
    // 机会
    SALES_OPPORTUNITY(XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), Arrays.asList(SalesOpportunityEnum.ESTIMATE_AMOUNT.getAttr(),
            SalesOpportunityEnum.PRODUCTS.getAttr() + StringConstant.POINT + SelectProductEnum.SUBTOTAL.getAttr(), SalesOpportunityEnum.PRODUCTS.getAttr() + StringConstant.POINT + SelectProductEnum.SELLING_PRICE.getAttr(),
            SalesOpportunityEnum.PRODUCTS.getAttr() + StringConstant.POINT + SelectProductEnum.DISCOUNT.getAttr())),

    // 采购合同
    PURCHASE(XbbRefTypeEnum.PURCHASE.getCode(), Arrays.asList(PurchaseEnum.TOTAL_MONEY.getAttr(), PurchaseEnum.PRODUCT_TOTAL.getAttr(),
            PurchaseEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.SUBTOTAL.getAttr())),
    // 采购退货单
    RETURNED_PURCHASE(XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), Arrays.asList(ReturnedPurchaseEnum.TOTAL_MONEY.getAttr(),
            ReturnedPurchaseEnum.PRODUCTS.getAttr() + StringConstant.POINT + SelectProductEnum.SUBTOTAL.getAttr())),
    // 装配单
    ASSEMBLE(XbbRefTypeEnum.ASSEMBLE.getCode(), Arrays.asList(
            AssembleEnum.OUT_PRODUCTS.getAttr() + StringConstant.POINT + SelectProductEnum.TOTAL_COST.getAttr(),
            AssembleEnum.IN_PRODUCTS.getAttr() + StringConstant.POINT + SelectProductEnum.TOTAL_COST.getAttr())
            ),

    // 其他入库单
    OTHER_INSTOCK(XbbRefTypeEnum.OTHER_INSTOCK.getCode(), Arrays.asList(
            InstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.TOTAL_COST.getAttr(),
            InstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.EXPIRE_DATE.getAttr())
    ),

    // 生产入库单
    PRODUCTION_INSTOCK(XbbRefTypeEnum.PRODUCTION_INSTOCK.getCode(), Arrays.asList(
            ProductionInstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.TOTAL_COST.getAttr(),
            ProductionInstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.EXPIRE_DATE.getAttr())
    ),
    // 生产退料单
    RETURNED_MATERIEL_INSTOCK(XbbRefTypeEnum.RETURNED_MATERIEL_INSTOCK.getCode(), Arrays.asList(
            ReturnedMaterielInstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.TOTAL_COST.getAttr(),
            ReturnedMaterielInstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.EXPIRE_DATE.getAttr()
            )),
    // 采购入库单
    PURCHASE_INSTOCK(XbbRefTypeEnum.PURCHASE_INSTOCK.getCode(), Arrays.asList(
            PurchaseInstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.TOTAL_COST.getAttr(),
            PurchaseInstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.EXPIRE_DATE.getAttr()
            )),
    // 销售退货入库单
    REFUND_INSTOCK(XbbRefTypeEnum.REFUND_INSTOCK.getCode(), Arrays.asList(
            RefundInstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.TOTAL_COST.getAttr(),
            RefundInstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.EXPIRE_DATE.getAttr(),
            RefundInstockEnum.PRODUCT_TOTAL.getAttr(),
            RefundInstockEnum.TOTAL_MONEY.getAttr()
            )),
    // 其他出库单
    OTHER_OUTSTOCK(XbbRefTypeEnum.OTHER_OUTSTOCK.getCode(), Arrays.asList(
            OutstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.TOTAL_COST.getAttr(),
            OutstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.EXPIRE_DATE.getAttr()
            )),
    // 销售出库单
    CONTRACT_OUTSTOCK(XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode(), Arrays.asList(
            ContractOutstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.TOTAL_COST.getAttr(),
            ContractOutstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.SUBTOTAL.getAttr(),
            ContractOutstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.EXPIRE_DATE.getAttr(),
            ContractOutstockEnum.PRODUCT_TOTAL.getAttr(),
            ContractOutstockEnum.TOTAL_MONEY.getAttr()
            )),
    // 出库发货单
    ORDER_OUTSTOCK(XbbRefTypeEnum.ORDER_OUTSTOCK.getCode(), Arrays.asList(
            OrderOutStockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.TOTAL_COST.getAttr(),
            OrderOutStockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.SUBTOTAL.getAttr(),
            OrderOutStockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.EXPIRE_DATE.getAttr(),
            OrderOutStockEnum.TOTAL_MONEY.getAttr()
            )),
    // 生产领料单
    PRODUCTION_MATERIEL_OUTSTOCK(XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK.getCode(), Arrays.asList(
            ProductionMaterielOutstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.TOTAL_COST.getAttr(),
            ProductionMaterielOutstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.EXPIRE_DATE.getAttr()
            )),
    // 采购退货出库单
    RETURNED_PURCHASE_OUTSTOCK(XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getCode(), Arrays.asList(
            ReturnedPurchaseOutstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.TOTAL_COST.getAttr(),
            ReturnedPurchaseOutstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.EXPIRE_DATE.getAttr())
            ),
    // 工单
    WORK_ORDER_OUTSTOCK(XbbRefTypeEnum.WORK_ORDER_OUTSTOCK.getCode(), Arrays.asList(
            WorkOrderOutstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.TOTAL_COST.getAttr(),
            WorkOrderOutstockEnum.PRODUCT.getAttr() + StringConstant.POINT + SelectProductEnum.EXPIRE_DATE.getAttr()
            )),
    // 成本调整单
    COST_ADJUST(XbbRefTypeEnum.COST_ADJUST.getCode(), Arrays.asList(
            CostAdjustEnum.PRODUCT.getAttr() + StringConstant.POINT + CostAdjustProductEnum.TOTAL_COST.getAttr(),
            CostAdjustEnum.PRODUCT.getAttr() + StringConstant.POINT + CostAdjustProductEnum.OLD_COST.getAttr(),
            CostAdjustEnum.PRODUCT.getAttr() + StringConstant.POINT + CostAdjustProductEnum.NEW_COST.getAttr(),
            CostAdjustEnum.PRODUCT.getAttr() + StringConstant.POINT + CostAdjustProductEnum.ADJUST_AMOUNT.getAttr()
            )),
    // 回执单
    RECEIPT_ORDER_PRODUCT(XbbRefTypeEnum.RECEIPT_ORDER.getCode(), Arrays.asList(
            "array_1" + StringConstant.POINT + SelectProductEnum.PRICE.getAttr(),
            "array_1" + StringConstant.POINT + SelectProductEnum.DISCOUNT.getAttr(),
            "array_1" + StringConstant.POINT + SelectProductEnum.SELLING_PRICE.getAttr(),
            "array_1" + StringConstant.POINT + SelectProductEnum.NUM.getAttr(),
            "array_1" + StringConstant.POINT + SelectProductEnum.SUBTOTAL.getAttr(),
            "array_2" + StringConstant.POINT + "num_1",
            "array_2" + StringConstant.POINT + "num_12",
            "array_2" + StringConstant.POINT + "num_13",
            "array_2" + StringConstant.POINT + "num_14",
            "array_2" + StringConstant.POINT + "num_15"
            )),

    WORK_ORDER_V2(XbbRefTypeEnum.WORK_ORDER_V2.getCode(),Arrays.asList("array_1" + StringConstant.POINT + SelectProductEnum.PRICE.getAttr(),
            "array_1" + StringConstant.POINT + SelectProductEnum.DISCOUNT.getAttr(),
            "array_1" + StringConstant.POINT + SelectProductEnum.SELLING_PRICE.getAttr(),
            "array_1" + StringConstant.POINT + SelectProductEnum.SUBTOTAL.getAttr()
            )),


    ;

    private Integer businessType;

    private List<String> fieldList;

    SystemFieldFormulaEnum(Integer businessType, List<String> fieldList) {
        this.businessType = businessType;
        this.fieldList = fieldList;
    }

    public static List<String> getFieldList(Integer businessType) {
        for (SystemFieldFormulaEnum systemFieldFormulaEnum: values()) {
            if (Objects.equals(systemFieldFormulaEnum.getBusinessType(), businessType)) {
                return systemFieldFormulaEnum.getFieldList();
            }
        }
        return new ArrayList<>();
    }
}
